#!/bin/bash
array_name=(1 2 3 4)
# 取得数组元素的个数
length=${#array_name[@]}
echo "1. length: "${length}
# 或者
length=${#array_name[*]}
echo "2. length: "${length}
# 取得数组单个元素的长度
length=${#array_name[n]}
echo "3. length: "${length}